﻿using System;

using Effects.Filters;

namespace EffectsPack
{
    /// <summary>
    ///  Combines 2 8th order filters in cascade to create bandpass filter.
    /// </summary>
    public class SixteenthOrderBandpass : Effects.Filters.Filter
    {
        /// <summary>
        ///  Low pass filter to cut high frequencies.
        /// </summary>
        private EighthOrderFilter lowFilter;

        /// <summary>
        ///  High pass filter to cut low frequencies
        /// </summary>
        private EighthOrderFilter highFilter;

        /// <summary>
        ///  Creates new 16th order filter with given bandpass boundary frequencies and sampling rate.
        /// </summary>
        /// <param name="frequencyLow"> Lower boundary fraquncy of desired bandpass. </param>
        /// <param name="frequencyUp"> Upper boundary fraquncy of desired bandpass. </param>
        /// <param name="sampleRate"> Sampling rate of input signal. </param>
        public SixteenthOrderBandpass(double frequencyLow, double frequencyUp, int sampleRate)
        {
            lowFilter = EighthOrderFilter.CreateLowPass(frequencyUp, sampleRate);
            highFilter = EighthOrderFilter.CreateHighPass(frequencyLow, sampleRate);
        }

        /// <summary>
        ///  Filters the signal.
        /// </summary>
        /// <param name="x0"> Sample of input signal.</param>
        /// <returns> Sample of filtered ouput signal. </returns>
        public override double Step(double x0)
        {
            return lowFilter.Step(highFilter.Step(x0));
        }

    }
}
